﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace SpeechRecognition.Domain.Input
{
    public class WavFileReader : IWavFileReader
    {
        public short[] Read(string fileName)
        {
            FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            int wordsToSkip = 44;
            long wordsCount = stream.Length / 2 - wordsToSkip;
            short[] result = new short[wordsCount];
            using (BinaryReader reader = new BinaryReader(stream))
            {
                for (int i = 0; i < wordsToSkip; i++)
                {
                    reader.ReadInt16();
                }

                for (int i = 0; i < wordsCount; i++)
                {
                    result[i] = reader.ReadInt16();
                }
            }

            return result;
        }
    }
}
